<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Yansongda\Pay\Pay;

class WxOrderController extends BaseController
{
    public function index(Request $request)
    {
        $param = $this->validate($request,[
            'scene' => 'required|in:1,2,3,4',
            'trade_no' => 'required'
        ]);

        $config = config('pay');
        switch ($param['scene']){
            case 1 :
                $config['wechat']['default']['notify_url'] = 'https://www.huashimu.com/api/ad/notify';
                break;
            case 2 :
                $config['wechat']['default']['notify_url'] = 'https://www.huashimu.com/api/course/notify';
                break;
            case 3 :
                $config['wechat']['default']['notify_url'] = 'https://www.huashimu.com/api/user/member/notify';
                break;
            case 4 :
                $config['wechat']['default']['notify_url'] = 'https://www.huashimu.com/api/user/gift/notify';
                break;
        }

        Pay::config($config);
        $result = Pay::wechat()->query([
            'out_trade_no' => $param['trade_no'],
            '_action' =>  'native'
        ]);
        return $this->success($result);
    }
}
